#ifndef _FORCO_OS_H_
#define _FORCO_OS_H_

#include <stddef.h>
#include <stdio.h>
#include "cpu.h"
#include "forco_os_config.h"
#include "stm32f2xx.h"
#include "cdfinger_common.h"
#include "core_cm3.h"
#include "task.h"
#include "tick.h"
#include "prio.h"
#include "rdylist.h"

//任务的状态
#define     OS_TASK_STATE_BIT_DLY                   (0x01)  //等待/超时位
#define     OS_TASK_STATE_BIT_PEND                  (0x02)  //等待位
#define     OS_TASK_STATE_BIT_SUSPENDED             (0x04)  //挂起

#define     OS_TASK_STATE_RDY                       (0x00)  //就绪
#define     OS_TASK_STATE_DLY                       (0x01)  //延时或者超时
#define     OS_TASK_STATE_PEND                      (0x02)  //等待状态
#define     OS_TASK_STATE_PEND_TIMEOUT              (0x03)  //等待超时
#define     OS_TASK_STATE_SUSPENDED                 (0x04)  //挂起
#define     OS_TASK_STATE_DLY_SUSPENDED             (0x05)  //挂起+延时
#define     OS_TASK_STATE_PEND_SUSPENDED            (0x06)  //挂起+等待
#define     OS_TASK_STATE_PEND_TIMEOUT_SUSPENDED    (0x07)  //挂起+等待+超时
#define     OS_TASK_STATE_DEL                       (0xFF)  //删除

//错误码
enum os_err{
    OS_ERR_NONE                 = 0 ,
    OS_ERR_ERROR                = 0x1000 ,
    OS_ERR_SYSTICK              = 0x1001,
    OS_ERR_CREATE               = 0x1002
};

//任务控制块
struct os_tcb{
    CPU_UINT32   *stkptr;              //任务的堆栈地址
    CPU_INT8     *taskname;            //任务的名字
    CPU_UINT32   taskprio;             //任务优先级 
    CPU_UINT32   TickCtrMatch;         //任务的到期时间点
    CPU_UINT32   TickRemain;           //任务的剩余时间
    OS_TCB       *NextPtr;             //下一个任务控制块
    OS_TCB       *PrevPtr;             //上一个任务控制块
    OS_TCB       *TCBTickNextPtr;      //时基的下一个任务控制块
    OS_TCB       *TCBTickPrevPtr;      //时基的上一个控制块
    OS_TICK_LIST *TickSpokePtr;        //这个tcb的在那个时基表上
    CPU_UINT8    TaskState;             //任务的状态
};


//时基表
struct os_tick_list{
    OS_TCB          *Ticknext; //下一个任务控制块是那个
    CPU_UINT32      TickCount;
};

//就绪表
struct os_rdy_list{
    OS_TCB          *RdylistHead;
    CPU_UINT32      RdyCount;
};

#endif


